package com.yuan.hospital.controller.api;

import com.yuan.hospital.common.result.Result;
import com.yuan.hospital.service.DepartmentService;
import com.yuan.hospital.service.HospitalService;
import com.yuan.hospital.service.HospitalSetService;
import com.yuan.hospital.service.ScheduleService;
import com.yuan.model.hospital.Hospital;
import com.yuan.vo.hosp.DepartmentVo;
import com.yuan.vo.hosp.HospitalQueryVo;
import com.yuan.vo.hosp.ScheduleOrderVo;
import com.yuan.vo.order.SignInfoVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 医院
 *
 * @Author yuan
 * @Date 2021/7/13 15:42
 */
@Api(tags = "医院列表及排班挂号相关信息")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private HospitalSetService hospitalSetService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "查询医院列表")
    @GetMapping("/findHospitalList/{page}/{limit}")
    public Result findHospitalList(@ApiParam(name = "page", value = "当前页码", required = true,defaultValue = "1") @PathVariable(required = false) Integer page, @ApiParam(name = "limit", value = "每页记录数", required = true,defaultValue = "10") @PathVariable Integer limit,HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.selectHospitalPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "根据医院名称查询医院信息")
    @GetMapping("/findByHosName/{hosName}")
    public Result findByHosName(@PathVariable String hosName) {
        List<Hospital> list = hospitalService.findByHospital(hosName);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据医院编号获取科室")
    @GetMapping("/department/{hosCode}")
    public Result index(@PathVariable String hosCode) {
        List<DepartmentVo> list = departmentService.findDeptTree(hosCode);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("{hoscode}")
    public Result getHospital(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }

    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("/findHospDetail/{hosCode}")
    public Result item(@PathVariable String hosCode) {
        Map<String, Object> map = hospitalService.item(hosCode);
        return Result.ok(map);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hosCode}/{depCode}")
    public Result getBookingSchedule(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Integer page, @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Integer limit, @ApiParam(name = "hosCode", value = "医院code", required = true) @PathVariable String hosCode, @ApiParam(name = "depCode", value = "科室code", required = true) @PathVariable String depCode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hosCode, depCode));
    }

    @ApiOperation(value = "获取排班数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "hosCode", value = "医院code", required = true),
            @ApiImplicitParam(paramType = "path", name = "depCode", value = "科室code", required = true),
            @ApiImplicitParam(paramType = "path", name = "workDate", value = "排班日期", required = true)
    })
    @GetMapping("auth/findScheduleList/{hosCode}/{depCode}/{workDate}")
    public Result findScheduleList(@PathVariable String hosCode, @PathVariable String depCode, @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hosCode, depCode, workDate));
    }
    @ApiOperation("根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        return Result.ok(scheduleService.getScheduleById(scheduleId));
    }
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@ApiParam(name = "scheduleId",value = "排班id",required = true)@PathVariable String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("/inner/getSignInfoVo/{hosCode}")
    public SignInfoVo getSignInfoVo(@ApiParam(name = "hosCode",value = "医院code",required = true)@PathVariable String hosCode){
        return hospitalSetService.getSignInfoVo(hosCode);
    }
}
